#!/bin/bash

##只是需要修改下面三个参数

serverName=test

TomcatUser=testuser

TomcatDir=/home/$TomcatUser/tomcat

TomcatLogFileName=$serverName.log

##只是需要修改上面三个参数

TomcatLogDir=$TomcatDir/log/$TomcatLogFileName

TomcatID=`ps -ef |grep tomcat |grep -w "$TomcatDir"|grep -v 'grep'|grep -v '/bin/bash'|awk 'NR==1 {print $2}'`

if [ $TomcatID ]
then
   echo '=============== restart ' $serverName ' tomcat ============'
   date -d today +"%Y-%m-%d %T"
   kill -9 $TomcatID
   echo 'sleep 2'
   sleep 2
   su - $TomcatUser  -c $TomcatDir"/bin/startup.sh" & tail -f $TomcatLogDir

else
    echo '=============== start ' $serverName ' tomcat ============'
    date -d today +"%Y-%m-%d %T"
    su - $TomcatUser  -c $TomcatDir"/bin/startup.sh" & tail -f $TomcatLogDir

fi
echo '=================  start ' $serverName ' tomcat end  =============='